package pers.linkong.asr.service;

import java.sql.Timestamp;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import pers.linkong.asr.domain.VRBean;
import pers.linkong.asr.domain.VRDateBean;
import pers.linkong.asr.mapper.VisualMapper;

@Service
// Service组件
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.SERIALIZABLE, readOnly = false)
public class VisualService {
	@Autowired
	private VisualMapper visualMapper;

	// 查询天数
	public long getDifference(int cid) throws Exception {
		return this.visualMapper.getDifference(cid);
	}
	
	// 
	public List<VRDateBean> getDate(int cid, int daynum) throws Exception {
		return this.visualMapper.getDate(cid, daynum);
	}
	
	// 根据课程id获取当前第几周
	public int getWeekNum(int cid, Timestamp date){
		Object temp = this.visualMapper.getWeekNum(cid,date);
		if(temp == null){
			return 0;
		}
		return (int)temp;
	}
	
	// 获取当天的学生记录
	public List<VRBean> getStuRecore(int cidSublevel, Timestamp date){
		return this.visualMapper.getStuRecore(cidSublevel, date);
	}
	
	/*// 增
	public void addVisual(VisualBean visual) throws Exception {
		this.visualMapper.addVisual(visual);
		this.visualMapper.addVisualClass(visual);
		System.out.println("添加学生：" + visual.getSid());
		// throw new RuntimeException();
	}

	// 删
	public void deleteVisual(int sid) throws Exception {
		this.visualMapper.deleteVisualClass(sid);
		this.visualMapper.deleteVisual(sid);
		System.out.println("删除学生：" + sid);
	}

	// 查
	public VisualBean getVisualById(int id) throws Exception {
		VisualBean visual = visualMapper.getVisualById(id);
		System.out.println("查询学生：" + visual.getSname());
		return visual;
	}
	
	// 查
	public List<ImageBean> getImageById(int id) throws Exception {
		System.out.println("查询图片：" + id);
		List<ImageBean> imagelist = visualMapper.getImageById(id);
		return imagelist;
	}
	
	// 改
	public void updateVisual(VisualBean visual) throws Exception {
		this.visualMapper.updateVisual(visual);
		this.visualMapper.updateVisualClass(visual);
		System.out.println("修改学生：" + visual.getSname());
	}

	// 分页
	public List<VisualBean> findVisualByPage(VisualBean visual, long start,
			long limit) throws Exception {
		List<VisualBean> visualBeans = this.visualMapper.findVisualByPage(visual, start, limit);
		return visualBeans;
	}
	
	// 统计
	public long getVisualCount(VisualBean visual) throws Exception {
		return this.visualMapper.getVisualCount(visual);
	}*/
	
}
